package zdream.control.foe.mmcommon;

import zdream.control.world.MFoe;
import zdream.control.world.buff.HealthModule;
import zdream.control.world.buff.SpoilsHolder;

/**
 * 怪死亡的时候, 原来怪的位置会有一个圈的动画, 然后添加掉落物.
 * 那个圈的动画就是 Ashes.
 *
 * @author Zdream
 * @since 0.0.1
 * @date 2022-06-12
 */
public class Ashes extends MFoe {
	public static final String NAME = "MMCommonAshes";

	public Ashes(MFoe foe) {
		super(foe.world);
	}

	@Override
	public String foeName() {
		return NAME;
	}

	@Override
	public void init() {
		this.type = TYPE_TEXTURE;
		this.side = SIDE_NONE;
		createHealthModule();
	}

	protected HealthModule createHealthModule() {
		return buildHealthModule()
					.maxAgeInMS(250)
					.create();
	}

	/* **********
	 *   行为   *
	 ********** */
	/**
	 * 怪物的掉落物, 一般的怪物被打掉之后会产生掉落物, 可能是螺丝 (货币)、加血的、加能量的等
	 */
	public SpoilsHolder spoilsBuilder;

	{
		onClean(this::dropSpoils);
	}

	public void dropSpoils(MFoe self) {
		if (spoilsBuilder == null) {
			return;
		}

		String foeName = spoilsBuilder.select();
		if (foeName == null) {
			return;
		}
		world.createFoe(foeName, anchorX, anchorY, true);
	}
}
